package cn.tdeu.spring.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;


@Configuration
public class JdbcTemplateConfig {

    @Bean
    public DataSource getDataSource () {

        DriverManagerDataSource dataSource =
                new DriverManagerDataSource();
        dataSource.setDriverClassName
                ("com.mysql.cj.jdbc.Driver");
        dataSource.setUrl
                ("jdbc:mysql://localhost:3306/test_db");
        dataSource.setUsername
                ("root");
        dataSource.setPassword
                ("root");

        return dataSource;

    }


        @Bean
        public JdbcTemplate getJdbcTemplate(DataSource dataSource) {
            return new JdbcTemplate(dataSource);
        }
    }

